From 80de2aa2eaa3b65949a9c71ae9303aeaf7df459a Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Sat, 25 May 2019 00:59:22 +0200 Subject: [PATCH] Add test for checkout_tree --- rust-bindings/rust/tests/repo.rs | 42 ++++++++++++++++++++++++++-- rust-bindings/rust/tests/util/mod.rs | 5 ++-- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/rust-bindings/rust/tests/repo.rs b/rust-bindings/rust/tests/repo.rs index c3a773c1..7f8a7d11 100644 --- a/rust-bindings/rust/tests/repo.rs +++ b/rust-bindings/rust/tests/repo.rs @@ -8,8 +8,9 @@ extern crate maplit; mod util; use util::*; +use gio::prelude::*; use gio::NONE_CANCELLABLE; -use ostree::prelude::*; +use glib::prelude::*; use ostree::{ObjectName, ObjectType}; #[test] @@ -31,7 +32,7 @@ fn should_commit_content_to_repo_and_list_refs_again() { #[test] fn should_traverse_commit() { let test_repo = TestRepo::new(); - let checksum = test_repo.test_commit(); + let checksum = test_repo.test_commit("test"); let objects = test_repo .repo @@ -61,3 +62,40 @@ fn should_traverse_commit() { objects ); } + +#[test] +fn should_checkout_tree() { + let test_repo = TestRepo::new(); + let _ = test_repo.test_commit("test"); + + let checkout_dir = tempfile::tempdir().expect("checkout dir"); + let file = test_repo + .repo + .read_commit("test", NONE_CANCELLABLE) + .expect("read commit") + .0 + .downcast::() + .expect("RepoFile"); + let info = file + .query_info("*", gio::FileQueryInfoFlags::NONE, NONE_CANCELLABLE) + .expect("file info"); + test_repo + .repo + .checkout_tree( + ostree::RepoCheckoutMode::User, + ostree::RepoCheckoutOverwriteMode::None, + &gio::File::new_for_path(checkout_dir.path().join("test-checkout")), + &file, + &info, + NONE_CANCELLABLE, + ) + .expect("checkout tree"); + + let testfile_path = checkout_dir + .path() + .join("test-checkout") + .join("testdir") + .join("testfile"); + let testfile_contents = std::fs::read_to_string(testfile_path).expect("test file"); + assert_eq!("test\n", testfile_contents); +} diff --git a/rust-bindings/rust/tests/util/mod.rs b/rust-bindings/rust/tests/util/mod.rs index 923a2f9b..8d92ea8a 100644 --- a/rust-bindings/rust/tests/util/mod.rs +++ b/rust-bindings/rust/tests/util/mod.rs @@ -1,7 +1,6 @@ use gio::NONE_CANCELLABLE; use glib::prelude::*; use glib::GString; -use ostree::prelude::*; use std::path::Path; #[derive(Debug)] @@ -23,9 +22,9 @@ impl TestRepo { TestRepo { dir, repo } } - pub fn test_commit(&self) -> GString { + pub fn test_commit(&self, ref_: &str) -> GString { let mtree = create_mtree(&self.repo); - commit(&self.repo, &mtree, "test") + commit(&self.repo, &mtree, ref_) } } -- 2.30.2